<template>
	<view class="periphery">
		<view class="header">
			<view class="header-left">研学周边</view>
			<view class="header-right" @click="toMerch">更多周边>></view>
		</view>
		<view class="list" v-if="!showLoading">
			<u-scroll-list :indicator="false" v-if="merchList.length>0">
				<view class="list-item" v-for="(item, index) in merchList" :key="index" @click="toMerchDetail(item.id)">
					<u--image width="300rpx" height="300rpx" radius="20rpx" :src="item.firstMedia" mode="aspectFill"></u--image>
					<view class="info">
						<view class="title oneline">{{item.name}}</view>
						<view class="subtitle">{{item.merchTypeName}}</view>
						<view class="subtitle">{{item.producer}}出品</view>
					</view>
				</view>
			</u-scroll-list>
			<view style="padding: 30rpx 0;" v-else>
				<u-empty mode="search" :iconSize="90" text="数据为空"></u-empty>
			</view>
		</view>
		<view class="skeleton" v-else>
			<u-row :gutter="30">
				<u-col span="5" v-for="item in 3" :key="index">
					<u-skeleton avatar avatarSize="150" avatarShape="square" :loading="showLoading"></u-skeleton>
					<view style="margin-top: 20rpx;">
						<u-skeleton rows="1" titleWidth="80%" title :loading="showLoading"></u-skeleton>
					</view>
				</u-col>
			</u-row>
		</view>
		<LoginModal ref="loginModal" />
	</view>
</template>

<script>
	import {
		checkLogin
	} from '@/utils/index.js';

	export default {
		props: {
			merchList: {
				type: Array,
				default: [],
			},
			showLoading: {
				type: Boolean,
				default: false,
			}
		},
		data() {
			return {
			}
		},
		methods: {
			toMerch() {
				uni.navigateTo({
					url: `/pages/study/merch`
				})
			},
			toMerchDetail(id) {
				if(checkLogin()) {
					uni.navigateTo({
						url: `/pages/study/merch-detail?id=${id}`
					})
				} else {
					this.$refs.loginModal.open();
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.periphery {
		margin-top: 40rpx;

		.header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			flex-direction: row;
			margin-bottom: 20rpx;

			&-left {
				font-size: 32rpx;
				color: #74BB2A;
			}

			&-right {
				// text-decoration-line: underline;
				// text-decoration-style: solid;
				color: #D7A768;
			}
		}

		.list {
			margin-left: -24rpx;
		}

		.list-item {
			flex-shrink: 0;
			position: relative;
			width: 300rpx;
			background-color: #fff;
			border-radius: 24rpx 24rpx 0 0;
			margin-left: 24rpx;

			image {
				width: 100%;
				height: 300rpx;
				border-radius: 24rpx;
			}


			.info {
				position: absolute;
				left: 0;
				bottom: 0;
				right: 0;
				background-color: #fff;
				padding: 16rpx;
				gap: 4px;
				border-radius: 0px 0px 24rpx 24rpx;
				background: linear-gradient(0deg, #000000 0%, rgba(102, 102, 102, 0) 183.29%);

				.title {
					font-size: 28rpx;
					color: #FFF;
				}

				.subtitle {
					font-size: 26rpx;
					color: rgba(255, 255, 255, 0.8);
				}
			}
		}
	}
</style>